/*
 * Copyright [2008] by Edward Chang
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package per.edward.wizard.ext;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.border.EmptyBorder;

import per.edward.wizard.ext.CustomDescriptor.WizardPanelWrapper;

public class AbstractWizardPanelWrapper implements WizardPanelWrapper {

    public WizardPanelProblemDisplayer wrap(Component comp) {
        JPanel contentPane = new JPanel(new BorderLayout());

        // create banner and store relevant components into a JPanel
        JPanel banner = new JPanel(new GridBagLayout());
        banner.setBackground(Color.WHITE);

        JLabel title = new JLabel(getTitle());
        Font font = title.getFont();
        title.setFont(font.deriveFont(font.getStyle() + Font.BOLD));
        title.setBorder(BorderFactory.createEmptyBorder(10, 10, 5, 5));

        JLabel desc = new JLabel(getDesc());
        desc.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));

        JLabel logo = new JLabel(getIcon());

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        banner.add(title, c);
        c.gridx = 1;
        c.gridheight = 2;
        banner.add(logo, c);
        c.gridx = 0;
        c.gridy = 1;
        c.gridheight = 1;
        c.weightx = 100;
        c.anchor = GridBagConstraints.PAGE_START;
        banner.add(desc, c);
        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 2;
        banner.add(new JSeparator(), c);

        // wrap provided component with a empty border
        JPanel center = new JPanel(new BorderLayout());
        center.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
        center.add(comp, BorderLayout.CENTER);

        // layout banner and center panel
        contentPane.add(banner, BorderLayout.NORTH);
        contentPane.add(center, BorderLayout.CENTER);

        return new WizardPanelProblemDisplayer(contentPane);
    }

    protected String getDesc() {
        return "Configure the M3O 2.0 server instance.";
    }

    protected String getTitle() {
        return "M3O Server Instance Configuration";
    }

    protected Icon getIcon() {
        return new ImageIcon(getClass().getClassLoader()
                .getResource("resources/images/logo.gif"));
    }
}
